﻿using Quartz.Impl;
using Quartz;

namespace CemsTransfer.BUS
{
    public class WorkService
    {
        public static async void ClearLog()
        {
            //调度器工厂
            ISchedulerFactory Work = new StdSchedulerFactory();
            //调度器
            IScheduler schedulers_work = await Work.GetScheduler();
            await schedulers_work.GetJobGroupNames();
            /*-------------计划任务代码实现------------------*/
            //创建任务
            IJobDetail job_Work = JobBuilder.Create<ClearLogJob>()
                .WithIdentity("ClearLog_TimeTrigger3", "ClearLog_TimeGroup3")
                .Build();
            //创建触发器 2点一分时被执行
            //每隔多久执行一次  这个是每隔多久执行一遍
            ITrigger trigger = TriggerBuilder.Create().WithIdentity("ClearLog_TimeTrigger3", "ClearLog_TimeGroup3").WithSimpleSchedule(t => t.WithIntervalInHours(24).RepeatForever()).Build();//间隔5分钟执行一次任务
            //添加任务及触发器至调度器中
            await schedulers_work.ScheduleJob(job_Work, trigger);
            /*-------------计划任务代码实现------------------*/
            //启动
            await schedulers_work.Start();
        }
    }
}
